<template>
  <a-modal
    :visible="visible"
    :title="$t('menu.replyInAdvance')"
    :width="1200"
    :bodyStyle="{
      'max-height': '76vh',
      overflow: 'auto'
    }"
    style="top: 20px;"
    :confirmLoading="confirmLoading"
    :okText="isCheck ? $t('button.SubmitReview') : $t('button.export') "
    @cancel="() => { $emit('cancel') }"
    @ok="confirm"
  >
    <detail-list :col="2">
      <detail-list-item :term="$t('key.xh')">{{ defendedInfo.xh }}</detail-list-item>
      <detail-list-item :term="$t('key.name')">{{ defendedInfo.xm }}</detail-list-item>
      <detail-list-item :term="$t('key.yx')">{{ defendedInfo.dwmc }}</detail-list-item>
      <detail-list-item :term="$t('key.zy')">{{ defendedInfo.zymc }}</detail-list-item>
      <detail-list-item :term="$t('key.yjfx')">{{ defendedInfo.yjfxmc }}</detail-list-item>
      <detail-list-item :term="$t('key.stuCate')">{{ defendedInfo.xslbmc }}</detail-list-item>
      <detail-list-item :term="$t('key.rxny')">{{ defendedInfo.rxny && defendedInfo.rxny.format('YYYY-MM-DD') }}</detail-list-item>
      <detail-list-item :term="$t('key.dsxm')">{{ defendedInfo.dsxm }}</detail-list-item>
      <detail-list-item :term="$t('key.kcxxqk')">{{ `已修${ defendedInfo.yxxf || 0.0 }学分` }}</detail-list-item>
      <detail-list-item :term="$t('key.ywcxqk')">{{ defendedInfo.ywcxkc }}</detail-list-item>
      <detail-list-item :term="$t('key.sfbygk')">{{ defendedInfo.sfbygkmc }}</detail-list-item>
    </detail-list>
    <detail-list :col="1">
      <detail-list-item :term="$t('key.lwtm')">{{ defendedInfo.lwtm }}</detail-list-item>
      <detail-list-item :term="$t('key.tmly')">{{ defendedInfo.tmly }}</detail-list-item>
    </detail-list>
    <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">{{$t('desc.replyDes1')}}</div>
    {{ defendedInfo.yqmbsxqk }}
    <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">{{$t('desc.replyDes2')}}</div>
    {{ defendedInfo.lwcxd }}
    <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">{{ $t('desc.replyDes3')}}</div>
    {{ defendedInfo.zxcgbj }}
    <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">{{ $t('desc.replyDes4')}}</div>
    {{ defendedInfo.wtyyy }}
    <a-form v-if="isCheck" :form="form">
      <div style="margin: 10px 0;font-weight: bold;font-size: 16px;">{{$t('desc.dsshjg')}}</div>
      <a-form-item
          :label="$t('key.reviewResult')"
          style="width:30%">
        <a-select v-decorator="['dsshzt',
          {
            rules: [{ required: true, message: $t('desc.dsshztCheck') }],
          }]" >
          <a-select-option value="03">{{$t('key.approved')}}</a-select-option>
          <a-select-option value="04">{{$t('key.fail')}}</a-select-option>
        </a-select>
      </a-form-item>
      <div style="margin: 10px 0;">{{$t('desc.dsjbpj')}}</div>
      <a-row :gutter="16">
        <a-col :md="8" :sm="12">
          <a-form-item :label="$t('key.lwyjsfcf')" >
            <a-select v-decorator="['dspjLwyjsfcf',
              {
                rules: [{ required: true, message: $t('desc.lwsfcfCheck') }],
              }]">
              <a-select-option v-for="i in TYPE0137" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="12">
          <a-form-item :label="$t('key.sfycxyj')" >
            <a-select v-decorator="['dspjSfycxyj',
              {
                rules: [{ required: true, message: $t('desc.sfycxyjCheck') }],
              }]">
              <a-select-option v-for="i in TYPE0065" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :md="8" :sm="12">
          <a-form-item :label="$t('key.ywsxpq')" >
            <a-select v-decorator="['dspjYwpqnr',
              {
                rules: [{ required: true, message: $t('desc.ywsxpqCheck') }],
              }]">
              <a-select-option v-for="i in TYPE0138" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
            </a-select>
          </a-form-item>
        </a-col>
      </a-row>
      <a-form-item
          :label="$t('key.dspjyj')">
        <a-textarea v-decorator="['dspjyj',
          {
            rules: [{ required: true, message: $t('desc.dspjyjCheck') }],
          }]" />
      </a-form-item>
    </a-form>
  </a-modal>

</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import DetailList from '~/tool/DetailList'
const DetailListItem = DetailList.Item

export default {
  props: ['visible', 'isCheck'],
  components: {DetailList, DetailListItem, STable},
  data () {
    return {
      form: this.$form.createForm(this),
      defendedInfo: {
      },
      tableData: [],
      confirmLoading: false,
      zjcolumns: [
        {
          title: '姓名',
          scopedSlots: { customRender: 'xm' }
        },
        {
          title: '职称',
          scopedSlots: { customRender: 'zc' }
        },
        {
          title: '所在单位、现从事专业',
          scopedSlots: { customRender: 'dw' }
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  computed: {
    ...mapState({
      TYPE0136: state => state.app['TYPE0136'],
      TYPE0139: state => state.app['TYPE0139'],
      TYPE0140: state => state.app['TYPE0140'],
      TYPE0141: state => state.app['TYPE0141'],
      TYPE0142: state => state.app['TYPE0142'],
      TYPE0143: state => state.app['TYPE0143'],
      TYPE0137: state => state.app['TYPE0137'],
      TYPE0065: state => state.app['TYPE0065'],
      TYPE0138: state => state.app['TYPE0138'],
    })
  },
  created () {
    this.$store.dispatch('app/setDictionary', 'TYPE0136')
    this.$store.dispatch('app/setDictionary', 'TYPE0139')
    this.$store.dispatch('app/setDictionary', 'TYPE0140')
    this.$store.dispatch('app/setDictionary', 'TYPE0141')
    this.$store.dispatch('app/setDictionary', 'TYPE0142')
    this.$store.dispatch('app/setDictionary', 'TYPE0143')
    this.$store.dispatch('app/setDictionary', 'TYPE0137')
    this.$store.dispatch('app/setDictionary', 'TYPE0065')
    this.$store.dispatch('app/setDictionary', 'TYPE0138')
  },
  methods: {
    newRow () {
      let hasEdit = this.tableData.find(d => {
        return d.editable
      })
      if (hasEdit) {
        return this.$message.warning('请先完成前面的添加')
      }
      this.tableData.push({
        xm: '',
        zc: '',
        dw: '',
        action: '',
        editable: true
      })
    },
    remove (index) {
      this.tableData.splice(index, 1)
    },
    completeAdd (data) {
      if (data.xm && data.zc && data.dw) {
        return this.$set(data, 'editable', false)
      }
      this.$message.error('请输入完整的评审专家信息')
    },
    confirm () {
      if (this.isCheck) {
        this.form.validateFields((err, values) => {
          if (err) return
          this.confirmLoading = true
          // if (!this.tableData.length) {
          //   return this.$message.error('评审专家不能为空')
          // }
          let params = Object.assign({
            ydbxxId: this.defendedInfo.id,
            // pszhjson: JSON.stringify(this.tableData)
          }, values)
          this.$api.cultivate.ydbCheck(params).then(res => {
            // console.log(res)
            this.$message.success(res.msg)
            this.$emit('cancel')
            this.$emit('refresh')
            this.confirmLoading = false
          })
        })
      } else {
        this.$export(`/teacherClient/ydbExp?id=${this.defendedInfo.id}`)
      }
    }
  }
}
</script>

<style>

</style>
